package norbert.controls {
	import mx.controls.Image;
	import mx.containers.HBox;
	import mx.core.ScrollPolicy;

	public class ImageNavigator extends HBox {
		/* PROPERTIES */
		
		private var image: Image;

		private var sourceChanged: Boolean = false;
		private var _source: Object;
		[Bindable]
		public function get source(): Object {
			return _source;
		}
		public function set source(value: Object): void {
			_source = value;
			sourceChanged = true;
			invalidateProperties();
		}
		
		/* CONSTUCTOR */

		public function ImageNavigator() {
			percentWidth = percentHeight = 100;
			horizontalScrollPolicy = verticalScrollPolicy = ScrollPolicy.OFF;
		}
		
		/* METHODS */

		override protected function createChildren():void {
			super.createChildren();

			if (!image) {
				image = new Image();
				image.scaleX = image.scaleY = .48;
				addChild(image);
			}
		}
		
		override protected function commitProperties(): void {
			super.commitProperties();
			
			if (sourceChanged && image) {
				sourceChanged = false;
				image.source = source;
			}
		}
	}
}
